/*
 * @Date: 2021-09-12 19:21:05
 * @Author: Acckno1
 * @LastEditTime: 2021-09-12 19:21:42
 * @Description: 
 */
#include <iostream>
#include <cstring>
#include <algorithm>
#include <map>
using namespace std;

const int N = 1010;

float nums[N];
int k, e;
float c;

int main () {
    memset(nums, 0, sizeof nums);
    cin >> k;
    for (int i = 0; i < k; i ++ ) {
        cin >> e >> c;
        nums[e] += c;
    }
    cin >> k;
    for (int i = 0; i < k; i ++ ) {
        cin >> e >> c;
        nums[e] += c;
    }
    
    int cnt = 0;
    for (int i = 0; i < N; i ++ )
        if (nums[i] != 0) cnt ++ ;
    printf("%d", cnt);
    for (int i = N - 1; i >= 0; i -- ) 
        if (nums[i] != 0) 
            printf(" %d %.1f", i, nums[i]);
    puts("");
    return 0;
}